home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / awe2-0_1.lha / awe2-0.1 / Src / RCS / OwnedFacility.cc,v < prev    next >
Text File  |  1989-05-05  |  3KB  |  185 lines

  1. head     3.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    grunwald:3.2; strict;
  6. comment  @@;
  7.  
  8.  
  9. 3.2
  10. date     89.02.20.15.36.25;  author grunwald;  state Exp;
  11. branches ;
  12. next     3.1;
  13.  
  14. 3.1
  15. date     88.12.20.13.49.03;  author grunwald;  state Exp;
  16. branches ;
  17. next     1.1;
  18.  
  19. 1.1
  20. date     88.10.30.13.03.15;  author grunwald;  state Exp;
  21. branches ;
  22. next     ;
  23.  
  24.  
  25. desc
  26. @@
  27.  
  28.  
  29. 3.2
  30. log
  31. @Start using Gnu library heaps for schedulers
  32. @
  33. text
  34. @#include "OwnedFacility.h"
  35. #include "FifoScheduler.h"
  36. #include "SimulationMultiplexor.h"
  37. #include "Thread.h"
  38. #include "assert.h"
  39. #include <math.h>
  40.  
  41. OwnedFacility::OwnedFacility(int xservers, ThreadContainer *xscheduler)
  42.     : (xservers, xscheduler)
  43. {
  44.     if (servers == 1) {
  45.     beingServiced.single = NULL;
  46.     } else {
  47.     beingServiced.many = new OwnedFacilityKey[servers];
  48.     for (register int i = 0; i < servers; i++) {
  49.         beingServiced.many[i] = NULL;
  50.     }
  51.     }
  52. }
  53.  
  54. //
  55. //    Facility will check that OwnedFacility is de-allocated
  56. //
  57. OwnedFacility::~OwnedFacility()
  58. {
  59. }
  60.  
  61. void
  62. OwnedFacility::commonReserve( double delayTime, OwnedFacilityKey xkey)
  63. {
  64.     dataLock.reserve();
  65.  
  66.     pTotalReserves++;
  67.     pTotalDelay += delayTime;
  68.  
  69.     if (servers == 1) {
  70.     if (whenServiced.single == NullTime) {
  71.         whenServiced.single = CurrentSimulatedTime;
  72.         beingServiced.single = xkey;
  73.         dataLock.release();
  74.         return;
  75.     }
  76.     } else {
  77.     for (int i = 0; i < servers; i++) {
  78.         if (whenServiced.many[i] == NullTime) {
  79.         beingServiced.many[i] = xkey;
  80.         whenServiced.many[i] = CurrentSimulatedTime;
  81.         dataLock.release();
  82.         return;
  83.         }
  84.     }
  85.     }
  86.     
  87.     dataLock.release();    // need to release so reportErrorState works
  88.  
  89.     reportErrorState(cerr);
  90.     assert2(FALSE, "[OwnedFacility] state error with facility semaphore");
  91. }
  92.  
  93. void OwnedFacility::reserve()
  94. {
  95.     double startedReserve = CurrentSimulatedTime;
  96.     Semaphore::reserve();
  97.     commonReserve(CurrentSimulatedTime - startedReserve,
  98.           ThisCpu -> CurrentThread() );
  99. }
  100.  
  101. bool OwnedFacility::reserveNoBlock()
  102. {
  103.     if (Semaphore::reserveNoBlock()) {
  104.     commonReserve(0.0, ThisCpu -> CurrentThread());
  105.     return(TRUE);
  106.     } else {
  107.     return(FALSE);
  108.     }
  109. }
  110.  
  111. void OwnedFacility::release()
  112. {
  113.     releaseKeyed(ThisCpu -> CurrentThread());
  114. }
  115.  
  116. void OwnedFacility::reserveKeyed(OwnedFacilityKey xkey)
  117. {
  118.     double start = CurrentSimulatedTime;
  119.     Semaphore::reserve();
  120.     commonReserve( CurrentSimulatedTime - start, xkey);
  121. }
  122.     
  123.     
  124. void OwnedFacility::releaseKeyed(OwnedFacilityKey xkey)
  125. {
  126.     dataLock.reserve();
  127.  
  128.     double now = CurrentSimulatedTime;
  129.     bool error;
  130.     
  131.     if (servers == 1) {
  132.     if (whenServiced.single != NullTime) {
  133.         totalServiceTime += (now - whenServiced.single);
  134.         whenServiced.single = NullTime;
  135.         error = (beingServiced.single != xkey);
  136.     } else {
  137.         error = 1;
  138.     }
  139.     } else {
  140.     for (int i = 0; i < servers; i++) {
  141.         if (whenServiced.many[i] != NullTime
  142.         && beingServiced.many[i] == xkey) {
  143.         totalServiceTime += (now - whenServiced.many[i]);
  144.         whenServiced.many[i] = NullTime;
  145.         break;
  146.         }
  147.     }
  148.     error = (i == servers);
  149.     }
  150.     
  151.     dataLock.release();
  152.  
  153.     if (error) {
  154.     cerr << " Attempted to release an un-reserved facility with key ";
  155.     cerr << hex(long(xkey)) << "\n";
  156.     reportErrorState(cerr);
  157.     exit(1);
  158.     }
  159.  
  160.     Semaphore::release();
  161. }
  162.  
  163. void OwnedFacility::classPrintOn(ostream &out)
  164. {
  165.     out << "OwnedFacility with " << activeServers() << " active servers and "
  166.     << queueLength() << " queued requests";
  167. }
  168. @
  169.  
  170.  
  171. 3.1
  172. log
  173. @Steay version
  174. @
  175. text
  176. @@
  177.  
  178.  
  179. 1.1
  180. log
  181. @Initial revision
  182. @
  183. text
  184. @@
  185.